package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.service.MasterRPCService;
import id.net.iconpln.bb.client.service.MasterRPCServiceAsync;
import id.net.iconpln.bb.client.service.TransportRPCService;
import id.net.iconpln.bb.client.service.TransportRPCServiceAsync;
import id.net.iconpln.bb.client.tools.ComboPembangkitPemasok;
import id.net.iconpln.bb.client.tools.ComboRakorPemasok;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.WidgetListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.store.StoreListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.MultiField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PageBbTransportSampling extends LayoutContainer {
	private final TransportRPCServiceAsync service = GWT.create(TransportRPCService.class);
	private final MasterRPCServiceAsync serviceMaster = GWT.create(MasterRPCService.class);
	private ListStore storePengajuan, storeResult, storeRakor, storeSampling, storeSurveyor;
	private Grid gridResult, gridBefore;
	private TextField txtTs, txtHgi, txtTm, txtNoSampling, txtNoPengajuan, txtVolume, txtJumlah, txtAsh, txtCv;
	private DateField txtTgl;
	private ComboBox cboRakor, cboPembangkit,cboSurveyor;
	
	  @Override  
	  protected void onRender(Element parent, int index) {  
	    super.onRender(parent, index);  
	    setLayout(new FitLayout());	    
	    initStore();
	    
	    ContentPanel cp = new ContentPanel();  	   
	    cp.setHeaderVisible(false);
	    cp.setFrame(true);  
	    cp.setLayout(new RowLayout(Orientation.HORIZONTAL));	  
	    
	    FormPanel panel = createForm(); 
	    panel.setScrollMode(Scroll.AUTO);
	    
	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);
	    p.setLayout(new RowLayout(Orientation.VERTICAL));	    
	    
	    ContentPanel cpShip = new ContentPanel();
	    cpShip.setLayout(new FitLayout());
	    gridBefore = createGridBefore();
	    gridBefore.addListener(Events.CellClick, new Listener<BaseEvent>() {            
            public void handleEvent(BaseEvent ge) {
            	txtNoPengajuan.setValue(gridBefore.getSelectionModel().getSelectedItem().get("no_pengajuan"));
            	txtTgl.setValue(new Date());  
            	
            	Map map = new FastMap();
            	map.put("id_pltu", cboPembangkit.getValue().get("id_pltu").toString());
            	map.put("id_pemasok", gridBefore.getSelectionModel().getSelectedItem().get("id_pemasok"));
            	serviceMaster.getMaster("SURVEYORBYPEMASOK_PENGAJUAN", map, new AsyncCallback<List<Map>>() {
        			public void onFailure(Throwable caught) {
        				GWT.log(caught.getMessage(), null);
        			}

        			public void onSuccess(List<Map> result) {	
        				storeSurveyor.removeAll();
        				storeSurveyor.add(ClientModule.setListBaseModelFromListMap(result));
        			}
        		});
            }
		});
	    cpShip.add(gridBefore);
	    
	    ToolBar tbJadwal = new ToolBar();
	    tbJadwal.add(new LabelToolItem("<b>Data Shipment</b>"));
	    tbJadwal.add(new SeparatorToolItem());
	    p.setTopComponent(tbJadwal);
	    
	    p.add(cpShip, new RowData(1, .5));
	    
	    ContentPanel cpLoading = new ContentPanel();
	    cpLoading.setHeading("Data Sampling");
	    cpLoading.setLayout(new FitLayout());
	    gridResult = createGridResult();
	    gridResult.addListener(Events.CellClick, new Listener<BaseEvent>() {            
            public void handleEvent(BaseEvent ge) {
            	txtNoPengajuan.setValue(gridResult.getSelectionModel().getSelectedItem().get("no_pengajuan"));
            	txtTgl.setRawValue(gridResult.getSelectionModel().getSelectedItem().get("tanggal").toString());  
            	txtNoSampling.setValue(gridResult.getSelectionModel().getSelectedItem().get("no_sampling"));
            	txtVolume.setValue(gridResult.getSelectionModel().getSelectedItem().get("vol_kirim"));
            	txtTs.setValue(gridResult.getSelectionModel().getSelectedItem().get("ts"));
            	txtHgi.setValue(gridResult.getSelectionModel().getSelectedItem().get("hgi"));
            	txtTm.setValue(gridResult.getSelectionModel().getSelectedItem().get("tm"));
            	txtAsh.setValue(gridResult.getSelectionModel().getSelectedItem().get("ash"));
            	txtCv.setValue(gridResult.getSelectionModel().getSelectedItem().get("cv"));
            	
            	
            	Map map = new FastMap();
            	map.put("id_pltu", cboPembangkit.getValue().get("id_pltu").toString());
            	map.put("id_pemasok", gridBefore.getSelectionModel().getSelectedItem().get("id_pemasok"));
            	serviceMaster.getMaster("SURVEYORBYPEMASOK_PENGAJUAN", map, new AsyncCallback<List<Map>>() {
        			public void onFailure(Throwable caught) {
        				GWT.log(caught.getMessage(), null);
        			}

        			public void onSuccess(List<Map> result) {	
        				storeSurveyor.removeAll();
        				storeSurveyor.add(ClientModule.setListBaseModelFromListMap(result));
        				
        				if(storeSurveyor.getModels().size() > 0){
        					cboSurveyor.setValue(storeSurveyor.getAt(0));
        				}
        			}
        		});
            }
		});
	    cpLoading.add(gridResult);
	    p.add(cpLoading, new RowData(1, .5));	
	    
	    cp.add(panel, new RowData(.40, 1));
	    cp.add(p, new RowData(.60, .99));	    
	    add(cp, new FitData(5)); 
	  }  
	  
	  private void getListPengajuan(String no_rakor, String status, String id_pltu){
		  Map mapParam = new FastMap();
  		  mapParam.put("no_rakor", no_rakor);
  		  mapParam.put("id_pltu", id_pltu);
  		  mapParam.put("status", status);
  		  
  		  service.getListPengiriman("PENGAJUAN", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storePengajuan.removeAll();
  				storePengajuan.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		  });
  		  
  		  service.getListPengiriman("SAMPLING", mapParam,new AsyncCallback<List<Map>>() {
  			public void onFailure(Throwable caught) {
  				GWT.log(caught.getMessage(), null);
  			}

  			public void onSuccess(List<Map> result) {	
  				storeSampling.removeAll();
  				storeSampling.add(ClientModule.setListBaseModelFromListMap(result));
  			}
  		  });
	  }
	  
	  private void initStore(){
		  storePengajuan = new ListStore(); 
		  storeRakor = new ListStore();
		  storeSampling = new ListStore();		  
		  storeResult = new ListStore(); 
		  storeSurveyor = new ListStore(); 
		  
		  storeResult.addStoreListener(new StoreListener<ModelData>(){
			  @Override
				public void storeAdd(StoreEvent<ModelData> se) {
					super.storeAdd(se);
					MessageBox.alert("Information", se.getModels().get(0).get("message").toString(), null);  
				}			  
		  });
	  }
	  
	  private Grid createGridBefore(){		    		  
		  List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	 
		    column = new ColumnConfig("no_jadwal", "No Jadwal", 150);  
		    configs.add(column);  
		    
		    column = new ColumnConfig("no_pengajuan", "No Pengajuan", 150);  
		    configs.add(column); 

		    column = new ColumnConfig("bulan_tahun", "BLTH", 100);  
		    configs.add(column);  	  
		    		  
		    column = new ColumnConfig("tanggal", "Tanggal", 100);  
		    configs.add(column);
		    
		    column = new ColumnConfig("id_transportir", "Transportir", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("id_kapal", "Kapal", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("volume", "Vol (Ton)", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("eta", "ETA", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("etd", "ETD", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("status", "Status", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("keterangan", "Keterangan", 150);  
		    configs.add(column);
		    storePengajuan.setMonitorChanges(true);  
		    ColumnModel cm = new ColumnModel(configs);
		    gridBefore = new Grid(storePengajuan, cm);  
		    gridBefore.getView().setEmptyText("Data Empty");  
		    gridBefore.setBorders(false);  	
		    return gridBefore;  
		  }   
	  
	  private FormPanel createForm() {  		
	    final FormPanel panel = new FormPanel();	    
	    panel.setHeaderVisible(false);
	    panel.setFrame(true);  
	    panel.setAction(GWT.getHostPageBaseURL() + "UploadHandler?jenis=sampling");  
	    panel.setEncoding(Encoding.MULTIPART);  
	    panel.setMethod(Method.POST);  
	    panel.setButtonAlign(HorizontalAlignment.CENTER);  
	    panel.setWidth(350);
	    
	    FieldSet fieldSetFilter = new FieldSet();  
	    fieldSetFilter.setHeading("Data Filter");  
	    fieldSetFilter.setCollapsible(false);
	    
	    FormLayout layoutFilter = new FormLayout();  
	    layoutFilter.setLabelWidth(100);  
	    fieldSetFilter.setLayout(layoutFilter);  
	    cboRakor = new ComboRakorPemasok(Registry.get("idPltu").toString());  
	    cboRakor.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
	    	@Override
	    	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
	    		Map map = new FastMap();
	    	    map.put("no_rakor", cboRakor.getValue().get("no_rakor").toString());
	    	    map.put("id_pemasok", Registry.get("idPltu").toString());
	    	    service.getListPengendalian("PEMBANGKIT_BY_RAKOR", map, new AsyncCallback<List<Map>>() {
	    			public void onFailure(Throwable caught) {
	    				GWT.log(caught.getMessage(), null);
	    			}

	    			public void onSuccess(List<Map> result) {	
	    				cboPembangkit.getStore().removeAll();
	    				cboPembangkit.getStore().add(ClientModule.setListBaseModelFromListMap(result));
	    			}
	    		});
	    	}
		});
	    fieldSetFilter.add(cboRakor);
	    
	    
	    cboPembangkit = new ComboPembangkitPemasok(Registry.get("idPltu").toString());
	    cboPembangkit.setWidth(200);
	    fieldSetFilter.add(cboPembangkit);
	    cboPembangkit.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
	    	@Override
	    	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
	    		getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "ENTRY", 
	    	  			  cboPembangkit.getValue().get("id_pltu").toString());	    		
	    	}
		});
	    
	    FieldSet fieldSet = new FieldSet();  
	    fieldSet.setHeading("Entry Sampling");  
	    fieldSet.setCollapsible(false);
	  
	    FormLayout layout = new FormLayout();  
	    layout.setLabelWidth(100);  
	    fieldSet.setLayout(layout);  
	    
	    txtNoSampling = new TextField();
	    txtNoSampling.setName("no_sampling");  
	    txtNoSampling.setFieldLabel("No Sampling");	    
	    fieldSet.add(txtNoSampling);
	    
	    txtNoPengajuan = new TextField();
	    txtNoPengajuan.setName("no_pengajuan");  
	    txtNoPengajuan.setFieldLabel("No Pengajuan");	
	    txtNoPengajuan.setAllowBlank(false);
	    fieldSet.add(txtNoPengajuan);
	    
	    txtTgl = new DateField(); 
	    txtTgl.setName("tanggal");
	    txtTgl.setPropertyEditor(new DateTimePropertyEditor("dd/MM/yyyy"));
	    txtTgl.setFieldLabel("Tanggal");  
	    txtTgl.setData("text", "Enter Tanggal");    
	    txtTgl.setAllowBlank(false);
	    fieldSet.add(txtTgl);	
	    
	    cboSurveyor = new ComboBox();  
	    cboSurveyor.setName("id_surveyor");  
	    cboSurveyor.setFieldLabel("Surveyor");
	    cboSurveyor.setEmptyText("Select Surveyor...");  
	    cboSurveyor.setDisplayField("nama_surveyor");  
	    cboSurveyor.setWidth(200);  
	    cboSurveyor.setStore(storeSurveyor);  
	    cboSurveyor.setTypeAhead(true);  
	    cboSurveyor.setTriggerAction(TriggerAction.ALL); 
	    cboSurveyor.setAllowBlank(false);
	    fieldSet.add(cboSurveyor);
	    
	    txtJumlah = new TextField();
	    txtJumlah.setName("jumlah_sampling");  
	    txtJumlah.setFieldLabel("Jumlah");	 
	    txtJumlah.setRawValue("1");
//	    fieldSet.add(txtJumlah);
	    
	    txtVolume = new TextField();
	    txtVolume.setName("volume");  
	    txtVolume.setFieldLabel("Volume");	   
	    txtVolume.setAllowBlank(false);
	    fieldSet.add(txtVolume);
	    
	    txtAsh = new TextField();
	    txtAsh.setName("ash");  
	    txtAsh.setFieldLabel("ASH");
	    txtAsh.setAllowBlank(false);	
	    txtAsh.setWidth(70);
	    
	    txtCv = new TextField();
	    txtCv.setName("cv");  
	    txtCv.setFieldLabel("CV");	 
	    txtCv.setAllowBlank(false);
	    txtCv.setWidth(70);
	    
	    MultiField mField1 = new MultiField();
	    mField1.setFieldLabel("ASH");
	    mField1.setSpacing(15);	    
	    mField1.add(txtAsh);
	    LabelField lFieldCv = new LabelField("CV");
	    lFieldCv.setWidth(30);
	    mField1.add(lFieldCv);
	    mField1.add(txtCv);	    
	    fieldSet.add(mField1);
	    
	    txtTm = new TextField();
	    txtTm.setName("tm");  
	    txtTm.setFieldLabel("TM");	
	    txtTm.setAllowBlank(false);
	    txtTm.setWidth(70);
	    
	    txtTs = new TextField();
	    txtTs.setName("ts");  
	    txtTs.setFieldLabel("TS");	
	    txtTs.setAllowBlank(false);
	    txtTs.setWidth(70);
	    
	    MultiField mField2 = new MultiField();
	    mField2.setFieldLabel("TM");
	    mField2.setSpacing(15);	    
	    mField2.add(txtTm);
	    LabelField lFieldTs = new LabelField("TS");
	    lFieldTs.setWidth(30);
	    mField2.add(lFieldTs);
	    mField2.add(txtTs);	    
	    fieldSet.add(mField2);
	    
	    txtHgi = new TextField();
	    txtHgi.setName("hgi");  
	    txtHgi.setFieldLabel("HGI");	
	    txtHgi.setAllowBlank(false);
	    txtHgi.setWidth(70);
	    fieldSet.add(txtHgi);
	    
	    final TextField txtNoSertifikat = new TextField();
	    txtNoSertifikat.setName("no_sertifikat");  
	    txtNoSertifikat.setFieldLabel("No. Sertifikat");	
	    txtNoSertifikat.setAllowBlank(false);
	    fieldSet.add(txtNoSertifikat);
	    
	    FileUploadField file = new FileUploadField();  
	    file.setAllowBlank(false);   
	    file.setName("uploadedfile");  
	    file.setFieldLabel("File");  
	    fieldSet.add(file); 
	    
	    panel.add(fieldSetFilter);
	    panel.add(fieldSet);  	

	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);	    
	    p.setButtonAlign(HorizontalAlignment.RIGHT);  
	    	    
	    p.addButton(new Button("Submit", new SelectionListener<ButtonEvent>() {  
	      @Override  
	      public void componentSelected(ButtonEvent ce) { 
//	    	  	Map mapParam = new FastMap();
//	    		mapParam.put("no_pengajuan", txtNoPengajuan .getRawValue());	    		
//	    		mapParam.put("jumlah_sampling", txtJumlah.getRawValue());
//	    		mapParam.put("ts", txtTs.getRawValue());
//	    		mapParam.put("hgi", txtHgi.getRawValue());
//	    		mapParam.put("tm", txtTm.getRawValue());
//	    		mapParam.put("volume", txtVolume.getRawValue());
//	    		mapParam.put("ash", txtAsh.getRawValue());
//	    		mapParam.put("cv", txtCv.getRawValue());
//	    		mapParam.put("tanggal", txtTgl.getRawValue());
//	    		mapParam.put("tgl_pengambilan", txtTgl.getRawValue());	
//	    		mapParam.put("user", Registry.get("whoAmI").toString());
//	    		mapParam.put("app_access", "WEB");
//	    		mapParam.put("status", "KIRIM");
//	    		mapParam.put("id_surveyor", cboSurveyor.getValue().get("id_surveyor").toString());
//	    		mapParam.put("no_sampling", txtNoSampling.getRawValue());
//	    		mapParam.put("id_pengiriman", "");
//	    		if (txtNoSampling.getRawValue().equals("")){
//	    			mapParam.put("crud", "CREATE");
//	    		}else{
//	    			mapParam.put("crud", "UPDATE");	    			
//	    		}
//	    		service.insertPengirimanBB("SAMPLING", mapParam,new AsyncCallback<List<Map>>() {
//	    			public void onFailure(Throwable caught) {
//	    				GWT.log(caught.getMessage(), null);
//	    			}
//	
//	    			public void onSuccess(List<Map> result) {	
//	    				storeResult.removeAll();
//	    				storeResult.add(ClientModule.setListBaseModelFromListMap(result));
//	    			
//	    				getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "SHIPMENT", 
//	  		    			  cboPembangkit.getValue().get("id_pltu").toString());
//	    			}
//	    		});
	    	  
	    	  if (!panel.isValid()) {  
		        	MessageBox.info("Action", "Failed ...................", null);  
		          return;  
		        }else{
		        	String url = GWT.getHostPageBaseURL() + "UploadHandler?jenis=sampling&no_sampling=" + txtNoSampling.getRawValue() + 
			    	  "&no_pengajuan=" +  txtNoPengajuan .getRawValue()	+  "&jumlah_sampling=" +  txtJumlah.getRawValue() + "&ts=" +  txtTs.getRawValue() + "&hgi=" +  txtHgi.getRawValue()
			    	  + "&tm=" +  txtTm.getRawValue() + "&ash=" +  txtAsh.getRawValue() + "&cv=" +  txtCv.getRawValue() + "&tanggal=" +  txtTgl.getRawValue() + "&tgl_pengambilan=" +  txtTgl.getRawValue()
			    	  + "&volume=" +  txtVolume.getRawValue() + "&user=" +  Registry.get("whoAmI").toString() + "&id_surveyor=" + "1" //cboSurveyor.getValue().get("id_surveyor").toString()
			    	  + "&no_sertifikat=" +  txtNoSertifikat.getRawValue();
			    	  panel.setAction(url); 
		    		panel.submit();
		        }
	    			
	      }  
	    }));  
	    
	    p.addButton(new Button("Delete", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {  
		    	  Map mapParam = new FastMap();
		    		mapParam.put("no_pengajuan", txtNoPengajuan .getRawValue());	    		
		    		mapParam.put("jumlah_sampling", txtJumlah.getRawValue());
		    		mapParam.put("ts", txtTs.getRawValue());
		    		mapParam.put("hgi", txtHgi.getRawValue());
		    		mapParam.put("tm", txtTm.getRawValue());
		    		mapParam.put("volume", txtVolume.getRawValue());
		    		mapParam.put("ash", txtAsh.getRawValue());
		    		mapParam.put("cv", txtCv.getRawValue());
		    		mapParam.put("tanggal", txtTgl.getRawValue());
		    		mapParam.put("tgl_pengambilan", txtTgl.getRawValue());		    		
		    		mapParam.put("user", Registry.get("whoAmI").toString());
		    		mapParam.put("app_access", "WEB");
		    		mapParam.put("status", "KIRIM");
		    		mapParam.put("id_surveyor", "0");
		    		mapParam.put("no_sampling", txtNoSampling.getRawValue());
	    			mapParam.put("crud", "DELETE");
	    			mapParam.put("id_pengiriman", "");
		    		service.insertPengirimanBB("SAMPLING", mapParam,new AsyncCallback<List<Map>>() {
		    			public void onFailure(Throwable caught) {
		    				GWT.log(caught.getMessage(), null);
		    			}
		
		    			public void onSuccess(List<Map> result) {	
		    				storeResult.removeAll();
		    				storeResult.add(ClientModule.setListBaseModelFromListMap(result));
		    				getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "SHIPMENT", 
					    			  cboPembangkit.getValue().get("id_pltu").toString());
		    				panel.reset();
		    			}
		    		});
		    		
		      }  
		    }));  
	    
	    p.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {  
		    	  panel.reset();
		      }  
		    }));  

	    panel.add(p);
	    
	    panel.addWidgetListener(new WidgetListener(){
	    	@Override
	    	public void handleEvent(ComponentEvent e) {
	    		// TODO Auto-generated method stub
	    		super.handleEvent(e);
//	    		getListPengajuan(cboRakor.getValue().get("no_rakor").toString(), "SHIPMENT", 
//		    			  cboPembangkit.getValue().get("id_pltu").toString());
	    	}
	    	
	    });
	    
	    return panel;  
	  }  

	  private Grid createGridResult(){
		    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig(); 
		    column = new ColumnConfig("no_sampling", "NO SAMPLING", 150);  
		    configs.add(column);  
		    
		    column = new ColumnConfig("tanggal", "TANGGAL", 150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig("no_pengajuan", "NO PENGAJUAN", 150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig("nama_surveyor", "SURVEYOR", 150);  
		    configs.add(column); 

		    column = new ColumnConfig("vol_kirim", "VOLUME", 100);  
		    configs.add(column);  	  
		    		  
		    column = new ColumnConfig("ash", "ASH", 100);  
		    configs.add(column);
		    
		    column = new ColumnConfig("cv", "CV", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("hgi", "HGI", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("tm", "TM", 150);  
		    configs.add(column);
		    
		    column = new ColumnConfig("ts", "TS", 150);  
		    configs.add(column);
		    
		    storeSampling.setMonitorChanges(true); 
		    ColumnModel cm = new ColumnModel(configs);  
		  
		    gridResult = new Grid(storeSampling, cm);  
		    gridResult.getView().setEmptyText("Data Empty");  
		    gridResult.setBorders(true);  
		  
		    return gridResult;  
	  }   

}
